package com.course.android.activity.ac;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContract;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.baselib.android.utils.Logger;
import com.course.android.R;
import com.course.android.activity.base.BaseActivity;
import com.course.dic.ActivityIntentKey;

public class IntentActivity extends BaseActivity implements View.OnClickListener {
    TextView tv, tv1, tv2;
    @Override
    protected void initView() {
        tv = findViewById(R.id.tv);
        tv1 = findViewById(R.id.tv1);
        tv2 = findViewById(R.id.tv2);
        tv.setOnClickListener(this);
//        tv1.setOnClickListener(this);
        tv2.setOnClickListener(this);
    }

    @Override
    protected void initData() {

    }


    @Override
    protected void onActivityResultCallBack(Integer reqCode,Intent data) {
        Bundle bundle = data.getExtras();
        if (bundle != null) {
            Logger.e(bundle.getString(ActivityIntentKey.RESP_TARGET_BUNDLE_PARAM1));
        }
    }

    @Override
    protected int bindLayout() {
        return R.layout.activity_intent;
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        intent.putExtra(ActivityIntentKey.REQ_INTENT_PARAM1, "from " + getClass().getName());
        if (v.getId() == R.id.tv) {
            intent.setClass(this, IntentTargetActivity.class);
            intent.putExtra(ActivityIntentKey.REQ_CODE,101);// 如果不需要标记返回结果就不用使用
            newIntentLauncher().launch(intent);
        }
        if (v.getId() == R.id.tv2) {
            intent.setAction("com.target");
            intent.putExtra(ActivityIntentKey.REQ_CODE,102);// 如果不需要标记返回结果就不用使用
            newIntentLauncher().launch(intent);
        }

    }
}
